﻿//-----------------------------------------------------------------------
// <copyright file="MainApp.cs" company="DylanBox">
// Copyright (c) DylanBox Corporation. All rights reserved.
// </copyright>
// <summary>
//      This real-world code demonstrates the Strategy pattern 
//      which encapsulates sorting algorithms in the form of sorting objects. 
//      This allows clients to dynamically change sorting strategies including Quicksort, Shellsort, and Mergesort. 
// </summary>
// <reference>
//      http://www.dofactory.com/Patterns/PatternStrategy.aspx#participants
//      http://www.cnblogs.com/DylanWind/archive/2008/11/26/1341236.html
// </reference>
// <author>Dylan</author>
//-----------------------------------------------------------------------

using System;
using System.Collections;

namespace SDFL.KeyPoints.DesignPattern.Strategy.RealWorld
{

    // MainApp test application 
    class MainApp
    {
        static void Main()
        {
            // Two contexts following different strategies 
            SortedList studentRecords = new SortedList();

            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();

            // Wait for user 
            Console.Read();
        }
    }
}

